//实现多态的代码

class Animal2 {
    public String name;
    public int age;
    public Animal2(String name, int age) {
        this.name = name;
        this.age = age;
    }
    public void eat() {
        System.out.println(this.name+"正在吃.......");
    }
}
class Dog2 extends Animal2 {
    public String color;
    public Dog2(String name,int age,String color) {
        super(name,age);
        this.color = color;
    }
    public void eat() {//与父类中的方法一样
        System.out.println(this.name+"正在吃狗粮");
    }
    public void sleep() {
        System.out.println(this.name+"正在睡觉");
    }
}
public class Test4 {
    public static void main(String[] args) {
        //Dog2 dog = new Dog2("李四",2,"黑色");
        Animal2 animal = new Dog2("旺财",2,"黑色");//向上转型
        animal.eat();
    }
}
